package alik.notes.client;

import java.util.Date;
import java.util.List;

import alik.notes.shared.data.Note;

import com.google.gwt.user.client.ui.FlexTable;

public class NotesTable extends FlexTable {

	public NotesTable() {
		super();
//		CellFormatter cellFormatter = new CellFormatter();
//		cellFormatter.se
//		this.setCellFormatter(cellFormatter );
		// setCellFormatter(new CellFormatter())
		// setColumnFormatter(new NotesColumnFormatter());
	}
	
	public void set(List<Note> notes) {
		clear();
		setStyleName(Style.notesTable.name());
		getRowFormatter().setStyleName(0, Style.notesTableHeader.name());
		setText(0, 0, "Title");
		setText(0, 1, "Description");
		setText(0, 2, "Creation Date");
//		resize(notes.size(), 3);
		int row = 0;
		for (Note note : notes) {
			++row;
			setRowData(row, note);
			getRowFormatter().setStyleName(row, Style.notesTableRow.name());
		}
	}
	// public class NotesColumnFormatter extends ColumnFormatter {
	//		
	// }

	private void setRowData(int row, Note note) {
		setText(row, 0, note.getTitle());
		setText(row, 1, note.getDescription());
		setText(row, 2, new Date(note.getLastEditDate()).toString().trim());
	}
}
